"""
购物：
    1.用户的账户里有钱
    2.用户可推一个空的购物车进商场
    3.开始购物，将自己想要的商品添加购物车
    4.打印购物小条
1.现在用户在进商场之前需要从10张优惠券中，随机抽取一张优惠券。
  比如抽到一个空凋的8折优惠券，后面在购物的过程中，空凋就可以按照8折后的价格来购买。
2.优化购物小条的人性化打印。
  购物时间，卡余额，购物数量，购买总商品的价值。
3.添加退货功能。在购买途中，某个商品不要了，退回到购物架中！
"""
import random
import time
money = 300
shoppingCart = []
goods = {
    "荷花": 35,
    "利群": 25,
    "芙蓉王": 26,
    "云龙": 15,
    "中华": 45
}
discount = {
    "荷花": 0.9,
    "利群": 0.8,
    "芙蓉王": 0.5,
    "云龙": 0.8,
    "中华": 0.9
}
random = random.randint(0, 4)
goods_list = ["荷花", "利群", "芙蓉王", "云龙", "中华"]
print("恭喜你,抽到", goods_list[random], "的优惠券")
goods[goods_list[random]] *= discount[goods_list[random]]
print(goods[goods_list[random]])
while True:
    shop = str(input("请输入你想购买的商品,退出购买请输入q/Q,退货请按T/t:"))
    if shop in goods:
        if money >= goods[shop]:
            shoppingCart.append(shop)
            money -= goods[shop]
            print("恭喜，购买成功!您的余额为:", money)
        else:
            print("余额不足")
    elif shop == "q" or shop == "Q":
        if len(shoppingCart) == 0:
            print("欢迎下次再来")
            break
        else:
            total = 0
            shop_sum = 0
            print("购物小票:")
            print("购物时间:", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
            for i in range(0, len(shoppingCart)):
                shop_sum += 1
                total += goods[shoppingCart[i]]
                print(shoppingCart[i], goods[shoppingCart[i]])
            print("购物数量:", shop_sum, "总价:", total, "卡余额:", money)
            break
    elif shop == "T" or shop == "t":
        cancel = input("请输入想退货的商品名称:")
        shoppingCart.remove(cancel)
        money += goods[cancel]
        print("退货成功,余额", money)
    else:
        print("暂无此商品")
